import { request } from './request'

/* -------------------- 类型 -------------------- */
export interface LoginResult {
  code: number
  message?: string
  token?: string
  data?: {
    token: string
    // ...其他字段
  }
}

/* -------------------- 用户登录 -------------------- */
export async function login(username: string, password: string): Promise<LoginResult> {
  if (!username || !password) {
    return { code: 400, message: '用户名或密码不能为空' }
  }

  // 走真实后端
  return request<LoginResult>({
    url: '/passport/signin',
    method: 'POST',
    data: { username, password }   // 后端要求字段名首字母大写
  })
}

/* -------------------- 用户登出 -------------------- */
export async function logout(): Promise<{ code: number; message: string }> {
  return request<{ code: number; message: string }>({
    url: '/auth/logout',
    method: 'POST'
  })
}

/* -------------------- 用户登出 -------------------- */
// export async function logout(): Promise<{ code: number; message: string }> {
//   const mockData = { code: 200, message: '已登出' }
//   return request<{ code: number; message: string }>(
//     {
//       url: '/auth/logout',
//       method: 'POST'
//     },
//     mockData
//   )
// }
